package com.sptpc.demo.global.response;


import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class GlobalResponse {

    private  Integer code;

    private String  msg;

    private Object data;

    //带数据的成功请求
    public static GlobalResponse success(Object data){
        return GlobalResponse.builder()
                .code(BusinessStatusCode.SUCCESS.getCode())
                .msg(BusinessStatusCode.SUCCESS.getMsg())
                .data(data)
                .build();
    }
    //不带数据的成功请求
    public static GlobalResponse success(){
    return success(null);
    }

    //失败
    public static GlobalResponse fail(BusinessStatusCode error){
        return GlobalResponse.builder()
                .code(error.getCode())
                .msg(error.getMsg())
                .data(null)
                .build();
    }
}
